package com.thyme.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.thyme.system.dao.Iec61850LnDao;
import com.thyme.system.service.Iec61850LnService;
import com.thyme.system.vo.Iec61850LnVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author nana
 * @since 2021-03-24
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class Iec61850LnServiceImpl implements Iec61850LnService {

    private final Iec61850LnDao iec61850LnDao;
    @Override
    public int updateLn(Iec61850LnVo iec61850LnVo) {
        QueryWrapper<Iec61850LnVo> queryWrapper = new QueryWrapper<Iec61850LnVo>();
        queryWrapper.eq("ln_inst_name",iec61850LnVo.getLnInstName());
        queryWrapper.eq("iec61850_ld_id",iec61850LnVo.getIec61850LdId());
        Iec61850LnVo tmp =  iec61850LnDao.selectOne(queryWrapper);
        if(tmp==null){
            iec61850LnDao.insertBy(iec61850LnVo);
        }else {
            iec61850LnDao.update(iec61850LnVo,queryWrapper);
            iec61850LnVo.setId(tmp.getId());
        }
        return iec61850LnVo.getId();
    }
}
